// To parse this data:
//
//   import { Convert, Zhihu } from "./file";
//
//   const zhihu = Convert.toZhihu(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.

import { useApi } from '@/hooks'
import { Ref, ref } from 'vue';

export interface Zhihu {
    data: number;
    list: List[];
}

export interface List {
    name:  string;
    query: string;
    url:   string;
}

export default async function useZhihu():Promise<Ref<Zhihu>> {
    const { response: result, request } = await useApi<Zhihu>('https://tenapi.cn/zhihuresou/');
    // 发起请求
    const loaded = ref(false)
    if (loaded.value === false) {
        await request();
        loaded.value = true;
    }
    return result;
}